Skip to content

Conversation

@yelizhenden-mdb
Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb commented Mar 21, 2025

Proposed changes

Jira ticket: CLOUDP-271999

Validates schema field names using the Spectral casing function

Drive-by fix: IPA-112: Avoid project field names will also check requestBody and response schemas similar to Field names must use camelCase

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Changes to Spectral

  • I have read the README file for Spectral Updates

Further comments

@yelizhenden-mdb yelizhenden-mdb marked this pull request as ready for review March 21, 2025 10:31
@yelizhenden-mdb yelizhenden-mdb requested a review from a team as a code owner March 21, 2025 10:31
Comment on lines 24 to 37
name: 'invalid schema',
document: {
components: {
schemas: {
SchemaName: {
properties: {
UserId: { type: 'string' },
user_id: { type: 'string' },
'user-id': { type: 'string' },
},
},
},
},
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Does it also catch nested schemas, and arrays etc.?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • It should catch nested schemas. I can add a unit test to be sure.
  • What do you mean by catching arrays in this context? Can you give an example?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

For arrays:

          ArraySchema: {
            type: 'array',
            items: {
              properties: {
                INVALID_FIELD: {},
              },
            },
          },

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the properties in items. Sure, let me add unit tests covering both and see how it works

- Reports any instances where these field names are not in camelCase format
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-112-field-names-are-camel-case'
severity: warn
given: '$.components.schemas..properties[*]~'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: WDYT about also targeting inline schemas? Or should we only check component.schemas?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! We should clarify what we mean by "field." To me, a field is a property of a resource schema, and resource schemas are typically defined under components.schemas. However, when I think about what I’d consider a resource schema, I’d primarily refer to response or requestBody content schemas as well.

So, are we specifically talking about inline schemas within those? Or, do we also count inline schemas used for query parameters? I’ve noticed that query parameters often use inline schemas, but they fall into a gray area—they're not path parameters, (the IPA for path params does not apply to them) and I’m not sure if their properties should be considered as fields

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think it could be valuable to catch fields in requests and responses as well, I'm working on the description IPA rule now and included them like so:

'$.paths[*][get,put,post,delete,options,head,patch,trace]..content..properties[*]'

In terms of query parameters, it's a good point. We don't talk a lot about them in the IPAs, but I'm thinking they should also be camelCase. Perhaps we can bring a new guideline for this. I think we can leave them out of this PR at least

@yelizhenden-mdb yelizhenden-mdb merged commit 93331b3 into main Mar 21, 2025
8 checks passed
@yelizhenden-mdb yelizhenden-mdb deleted the CLOUDP-271999 branch March 21, 2025 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants